package com.ruoyi.system.service;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.RuoYiApplication;
import com.ruoyi.common.utils.CalcUtil;
import com.ruoyi.common.utils.NewDateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.UIDUtil;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.uitl.ImportBasicExcelUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@RunWith(SpringRunner.class)
//@SpringBootTest(classes = RuoYiApplication.class)
public class ImportPicExcelTest {
    private static final Logger logger = LoggerFactory.getLogger(ImportPicExcelTest.class);
    static ClassPathResource classPathResource = new ClassPathResource("face.xlsx");



    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ImportBasicExcelUtil.timeformatter2);



    @Test
    public void start() throws SQLException {
        List<Map<String,String>> result_1 = ReadExcel();
        for (int number = 0; number < result_1.size(); number++) {
            handleEveryLine(result_1.get(number), number+1);
        }
    }

    public List<Map<String,String>> ReadExcel() {
        try{
            //读取EXCEL
            List<List<Map<String,String>>> result = ImportBasicExcelUtil.readExcelWithTitle(classPathResource);
            List<Map<String,String>> result_1 =  result.get(0);
            logger.info("************************************");
            logger.info("************excel读取成功************");
            logger.info("************************************");
            return result_1;
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public void handleEveryLine(Map<String, String> map, int number) {

        try{
            if(StringUtils.isEmpty(map.get("项目编号"))){
                logger.error("第{}行插入失败，项目编号为空，整行内容：{}", number+1, JSON.toJSONString(map));
                return;
            }


            logger.info("第{}行插入成功，项目编号为:{}，整行内容：{}", number+1, map.get("项目编号"), JSON.toJSONString(map));
        }catch(Exception e){
            e.printStackTrace();
            logger.error("第{}行异常，项目编号为:{}，整行内容：{}", number+1, map.get("项目编号"), JSON.toJSONString(map));
        }finally{

        }
    }




}
